<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <p>
        <span>-</span>
        <input type="text" value="1" disabled>
        <span>+</span>
    </p>

    <p>
        <span>-</span>
        <input type="text" value="2" disabled>
        <span>+</span>
    </p>
    <p>
        <span>-</span>
        <input type="text" value="4" disabled>
        <span>+</span>
    </p>

    <script>

        var oAdds = document.querySelectorAll('p span:last-child');
        console.log(oAdds);
        var oJians = document.querySelectorAll('p span:first-child');
        console.log(oJians);


        // 加法
        for (var i = 0; i < oAdds.length; i++) {
            oAdds[i].onclick = function () {
                this.previousElementSibling.value++;
            }
        }

        for (var i = 0; i < oJians.length; i++) {
            oJians[i].onclick = function () {
                if (this.nextElementSibling.value == 1) {
                    alert('数量不能小于1')
                } else {
                    this.nextElementSibling.value--;
                }

            }
        }


    </script>

</body>

</html>